package com.lemon.blog.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import com.lemon.blog.web.domain.BlCommentOptions;
import com.lemon.blog.web.service.BlCommentOptionsService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.page.TableDataInfo;

/**
 * 包名称：com.lemon.blog.web.controller
 * 类名称：BlCommentOptionsController
 * 类描述：评论相关操作Controller
 * 创建人：@author lemon
 * 创建时间：2023-08-18
 */
@Api("评论相关操作")
@RestController
@RequestMapping("/commentOptions")
public class BlCommentOptionsController extends BaseController {

    @Autowired
    private BlCommentOptionsService blCommentOptionsService;

    /**
     * 查询评论相关操作列表
     * @Title: list
     * @Description: 查询评论相关操作列表
     * @param blCommentOptions 评论相关操作
     * @return: TableDataInfo
     * @throws:
     * @author: lemon
     * @Date: 2023-08-18
     */
    @GetMapping("/list")
    public TableDataInfo list(BlCommentOptions blCommentOptions) {
        startPage();
        List<BlCommentOptions> list = blCommentOptionsService.selectBlCommentOptionsList(blCommentOptions);
        return getDataTable(list);
    }

    /**
     * 导出评论相关操作列表
     * @Title: export
     * @Description: 导出评论相关操作列表
     * @param response 客户端响应对象
     * @param blCommentOptions 评论相关操作
     * @return:
     * @throws:
     * @author: lemon
     * @Date: 2023-08-18
     */
    @RequiresPermissions("blogWeb:options:export")
    @Log(title = "评论相关操作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlCommentOptions blCommentOptions) {
        List<BlCommentOptions> list = blCommentOptionsService.selectBlCommentOptionsList(blCommentOptions);
        ExcelUtil<BlCommentOptions> util = new ExcelUtil<BlCommentOptions>(BlCommentOptions.class);
        util.exportExcel(response, list, "评论相关操作数据");
    }

    /**
     * 获取评论相关操作详细信息
     * @Title: getInfo
     * @Description: 获取评论相关操作详细信息
     * @param id 评论相关操作主键
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-08-18
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(blCommentOptionsService.selectByPrimaryKey(id));
    }

    /**
     * 新增或更新评论相关操作
     * @Title: insertOrUpdate
     * @Description: 新增或更新评论相关操作
     * @param blCommentOptions 评论相关操作
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-08-18
     */
    @Log(title = "评论相关操作", businessType = BusinessType.INSERT)
    @PostMapping("insertOrUpdate")
    public AjaxResult insertOrUpdate(@RequestBody BlCommentOptions blCommentOptions) {
        return toAjax(blCommentOptionsService.insertOrUpdate(blCommentOptions));
    }

    /**
     * 修改评论相关操作
     * @Title: edit
     * @Description: 修改评论相关操作
     * @param blCommentOptions 评论相关操作
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-08-18
     */
    @Log(title = "评论相关操作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlCommentOptions blCommentOptions) {
        return toAjax(blCommentOptionsService.update(blCommentOptions));
    }

    /**
     * 删除评论相关操作
     * @Title: remove
     * @Description: 删除评论相关操作
     * @param ids 需要删除的评论相关操作主键集合
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-08-18
     */
    @Log(title = "评论相关操作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blCommentOptionsService.deleteByBatch(ids));
    }
}
